#from tkinter import Y
import matplotlib.pyplot as plt
import numpy as np
file_name1 = "C1.txt"
file_name2 = "C2.txt"
a = []
b = []
file1 = open(file_name1, mode = 'r')
for line in file1:
    line = line.split()
    a.append(line)
file1.close()

file2 = open(file_name2, mode = 'r')
for line in file2:
    line = line.split()
    b.append(line)
file2.close()

a1 = []
for m in a:
    a1.append(float(m[0]))
a = a1#将list转化为int
b1 = []
for m in b:
    b1.append(float(m[0]))
b = b1

x = np.linspace(-1,1,10000)
y = 1/(1+25*x*x)
Y = np.zeros((10000,4))

n = [5, 10, 15, 20]
for i in range(0,4):
    if i == 0:
            p = 0
            q = n[0]
    else:
        p = q
        q = q + n[i]
    for k in range(0, 10000):
        for j in range(p, q):
            if j == p:
                Y[k][i] = a[q-1]
            else:
                Y[k][i] = Y[k][i]*(x[k]-b[q - (j-p+1)]) + a[q - (j-p+1)]
        #print(Y[k][i])
Y1 = np.array(Y)

for i in range(0, 4):
    plt.plot(x,Y1[:,i])

plt.plot(x,y,'--')
plt.legend(['n=5','n=10','n=15','n=20'])
plt.show()
plt.savefig("C.png")